/** @file         lzm_atomic.c
 *  @brief        简要说明
 *  @details      详细说明
 *  @author       lzm
 *  @date         2021-06-10 16:49:46
 *  @version      v1.0
 *  @copyright    Copyright By lizhuming, All Rights Reserved
 *
 **********************************************************
 *  @LOG 修改日志:
 **********************************************************
*/


#include "lzm_atomic.h"

void lzm_atomic_init(lzm_atomic_t *atomic_x, int num)
{
	pthread_mutex_init(&atomic_x->mutex, NULL);	
    atomic_x->num = num;
}

void lzm_atomic_add(lzm_atomic_t *atomic_x)
{
	pthread_mutex_lock(&atomic_x->mutex);	
    atomic_x->num++;
	pthread_mutex_unlock(&atomic_x->mutex);	
}


void lzm_atomic_sub(lzm_atomic_t *atomic_x)
{
	pthread_mutex_lock(&atomic_x->mutex);	
    atomic_x->num--;
	pthread_mutex_unlock(&atomic_x->mutex);	
}

void lzm_atomic_set(lzm_atomic_t *atomic_x, int num)
{
	pthread_mutex_lock(&atomic_x->mutex);	
    atomic_x->num = num;
	pthread_mutex_unlock(&atomic_x->mutex);	
}


int lzm_atomic_get(lzm_atomic_t *atomic_x)
{
    return atomic_x->num;
}
